﻿using System;
using System.Web;

namespace KPIS.GERP.Models.Class
{
	public static class CookieUtility
	{
		public static void Set(string key, string value)
		{
			if (Cookie(key) == null)
			{
				var newCookie = new HttpCookie(key, value);
				newCookie.Expires = DateTime.Now.AddYears(1);
				HttpContext.Current.Response.AppendCookie(newCookie);
			}
			else
			{
				var oldCookie = Cookie(key);
				oldCookie.Value = value;
				HttpContext.Current.Response.SetCookie(oldCookie);
			}
		}

		public static string Get(string key)
		{
			if (Cookie(key) != null)
				return Cookie(key).Value;

			return string.Empty;
		}

		public static void Remove(string key)
		{
			if (Cookie(key) != null)
				HttpContext.Current.Response.Cookies.Remove(key);
		}

		public static HttpCookie Cookie(string key)
		{
			return HttpContext.Current.Request.Cookies[key];
		}
         
	}
}
